var time = 3;
var hy = 'A01';
//地图容器
var chart2 = echarts.init(document.getElementById('main2'));
//34个省、市、自治区的名字拼音映射数组
var provinces = {
    //23个省
    "台湾": "taiwan",
    "河北": "hebei",
    "山西": "shanxi",
    "辽宁": "liaoning",
    "吉林": "jilin",
    "黑龙江": "heilongjiang",
    "江苏": "jiangsu",
    "浙江": "zhejiang",
    "安徽": "anhui",
    "福建": "fujian",
    "江西": "jiangxi",
    "山东": "shandong",
    "河南": "henan",
    "湖北": "hubei",
    "湖南": "hunan",
    "广东": "guangdong",
    "海南": "hainan",
    "四川": "sichuan",
    "贵州": "guizhou",
    "云南": "yunnan",
    "陕西": "shanxi1",
    "甘肃": "gansu",
    "青海": "qinghai",
    //5个自治区
    "新疆": "xinjiang",
    "广西": "guangxi",
    "内蒙古": "neimenggu",
    "宁夏": "ningxia",
    "西藏": "xizang",
    //4个直辖市
    "北京": "beijing",
    "天津": "tianjin",
    "上海": "shanghai",
    "重庆": "chongqing",
    //2个特别行政区
    "香港": "xianggang",
    "澳门": "aomen"
};

//直辖市和特别行政区-只有二级地图，没有三级地图
var special = ["北京","天津","上海","重庆","香港","澳门"];
var mapdata = [];
//绘制全国地图
$.getJSON('js/map/map/china.json', function(data){
	d = [];
	for( var i=0;i<data.features.length;i++ ){

		d.push({
			name:data.features[i].properties.name,
			id :data.features[i].id.substring(0, 3),
		})
	}
	mapdata = d;
	//注册地图
	echarts.registerMap('china', data);
	//绘制地图
	renderMap2('china',d);
});


//初始化绘制全国地图配置
var option2 = {
	backgroundColor: '#ebebeb',
    title : {
        text: '全国农业专利',
        //subtext: '三级下钻',
        left: 'center',
        textStyle:{
            fontSize:18,
            fontWeight:'normal',
            fontFamily:"Microsoft YaHei"
        },
        subtextStyle:{
            fontSize:14,
            fontWeight:'normal',
            fontFamily:"Microsoft YaHei"
        }
    },
    	 visualMap: {
        min: 0,
        max: 100,
        left: 'left',
       // color: ['orangered','yellow','lightskyblue'],
        top: 'bottom',
        text:['高','低'],           // 文本，默认为数值文本
        calculable : true
    },
    tooltip: {
        trigger: 'item',
        formatter: '{b}'
    },

    animationDuration:1000,
	animationEasing:'cubicOut',
	animationDurationUpdate:1000
     
};
function renderMap2(map,data){
		var param = []
	for(var i = 0; i < data.length; i++) {
		param.push(JSON.stringify(data[i]))
	}
	axios({
		method: 'POST',
		url: base_url + '/map2',
		params: {
			"jsonarr": param,
			"time": time,
			"hy": hy
		},
		responseType: 'json',
	}).then(function(res){
		var acdata = res.data.data
		
		  option2.series = [ 
		{
            name: map,
            type: 'map',
            mapType: map,
            roam: false,
            label: {
	            normal:{
					show:true,
					textStyle:{
						fontSize:13
					},
					formatter: function(data) {

						return data.value;

					},
	            },
	            emphasis: {
	                show: true,
	                textStyle:{
						fontSize:13
					}
	            },
	        },
	        itemStyle: {
	           		emphasis: {
						borderWidth: 1,
					borderColor: '#a5a082',
				}
	        },
            data:acdata
        }	
    ];
    //渲染地图
    chart2.setOption(option2);
		
	})

}



//切换行业
function switchHy(type, e) {
	$('.hy2').each(function() {
		$(this).find('a').removeClass('active')
	})
	$(e).addClass("active")
	hy = type
$.getJSON('js/map/map/china.json', function(data){
	d = [];
	for( var i=0;i<data.features.length;i++ ){
		d.push({
			name:data.features[i].properties.name,
			id :data.features[i].id.substring(0, 3),
		})
	}
	mapdata = d;
	//注册地图
	echarts.registerMap('china', data);
	//绘制地图
	renderMap2('china',d);
});
}

//切换规模
function switchTm(t, e) {

	$('.tm').each(function() {
		$(this).find('a').removeClass('active')
	})
	$(e).addClass("active")
	time = t

	$.getJSON('js/map/map/china.json', function(data){
	d = [];
	for( var i=0;i<data.features.length;i++ ){
		d.push({
			name:data.features[i].properties.name,
			id :data.features[i].id.substring(0, 3),
		})
	}
	mapdata = d;
	//注册地图
	echarts.registerMap('china', data);
	//绘制地图
	renderMap2('china',d);
});
}
